﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace SARUserControls
{
	/// <summary>
	/// SARImageTextButton.xaml 的交互逻辑
	/// </summary>
	public partial class SARImageTextButton : UserControl
	{
		public SARImageTextButton()
		{
			this.InitializeComponent();
		}

        /// <summary>
        /// 图片路径
        /// </summary>
        public string SARImageSource
        {
            set
            {
                this.imgIcon.Source = new BitmapImage(new Uri(value, UriKind.RelativeOrAbsolute));
            }
            get
            {
                return this.imgIcon.Source.ToString();
            }
        }

        /// <summary>
        /// 文本
        /// </summary>
        public string SARText
        {
            set
            {
                this.txtLabel.Text = value;
            }
            get
            {
                return this.txtLabel.Text;
            }
        }
		
		public double SARImageWidth
		{
			set
			{
				this.imgIcon.Width = value;
				this.txtLabel.Margin = new Thickness(value+4,0,0,0);
			}
		}
		
		public double SARImageHeight
		{
			set
			{
				this.imgIcon.Height = value;
			}
		}
	
		

        /// <summary>
        /// 单击事件
        /// </summary>
        public event MouseButtonEventHandler SARClick;

        private void gridMouseCapture_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            this.gridContent.Margin = new Thickness(1, 1, 0, 0);
            if (SARClick != null)
            {
                SARClick.Invoke(this, e);
            }
        }

        private void gridMouseCapture_MouseLeave(object sender, MouseEventArgs e)
        {
            this.gridContent.Margin = new Thickness(0, 0, 0, 0);
        }

        private void gridMouseCapture_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            this.gridContent.Margin = new Thickness(0, 0, 0, 0);
        }
	}
}